local skel = fk.CreateSkill {
  name = "rmt__diaozhuoguimu",
}

Fk:loadTranslationTable{
  ["rmt__diaozhuoguimu"] = "凋灼瑰幕",
  [":rmt__diaozhuoguimu"] = "游戏开始或回合结束时，你可以扣减体力上限至体力值，每扣减1点，你便摸一张牌并获得1点护甲。你于回合外因伤害失去护甲后，直至你的回合开始，你于每回合结束时受到1点火焰伤害。",

  ["#rmt__diaozhuoguimu-invoke"] = "凋灼瑰幕：你可以扣减 %arg 点体力上限，摸等量牌，获得等量护甲",
  ["@@rmt__diaozhuoguimu"] = "<font color='#F03131'>凋灼瑰幕</font>",

  ["$rmt__diaozhuoguimu1"] = "Skin must be peeled while warm — cold flesh betrays my brush.（剥皮要趁热，冰冷的皮肤会辜负我的画笔。）",
  ["$rmt__diaozhuoguimu2"] = "The sweeter the scream, the deeper the rose blooms.（惨叫愈动听，玫瑰愈艳红。）",
}

local DIY = require "packages.diy_utility.diy_utility"
local U = require "packages.utility.utility"

local on_cost = function (self, event, target, player, data)
  return player.room:askToSkillInvoke(player, {skill_name = skel.name, prompt = "#rmt__diaozhuoguimu-invoke:::"..player:getLostHp() })
end

---@param player ServerPlayer
local on_use = function (self, event, target, player, data)
  local room = player.room
  local x = player.maxHp - player.hp
  room:changeMaxHp(player, -x)
  if player.dead then return false end
  player:drawCards(x, skel.name)
  room:changeShield(player, x)
end

skel:addEffect(fk.GameStart, {
  anim_type = "drawcard",
  can_trigger = function (self, event, target, player, data)
    return player:hasSkill(skel.name) and player.maxHp > player.hp
  end,
  on_cost = on_cost,
  on_use = on_use,
})

skel:addEffect(fk.TurnEnd, {
  anim_type = "drawcard",
  can_trigger = function (self, event, target, player, data)
    return player:hasSkill(skel.name) and player.maxHp > player.hp and target == player
  end,
  on_cost = on_cost,
  on_use = on_use,
})


skel:addEffect(fk.HpChanged, {
  anim_type = "negative",
  can_trigger = function (self, event, target, player, data)
    return target == player and player:hasSkill(skel.name) and player.phase == Player.NotActive
    and player:getMark("@@rmt__diaozhuoguimu") == 0 and data.shield_lost and data.shield_lost > 0
  end,
  on_cost = Util.TrueFunc,
  on_use = function (self, event, target, player, data)
    player.room:setPlayerMark(player, "@@rmt__diaozhuoguimu", 1)
  end,
})


skel:addEffect(fk.TurnEnd, {
  is_delay_effect = true,
  anim_type = "negative",
  can_trigger = function (self, event, target, player, data)
    return not player.dead and player:getMark("@@rmt__diaozhuoguimu") ~= 0
  end,
  on_cost = Util.TrueFunc,
  on_use = function (self, event, target, player, data)
    player.room:damage { from = nil, to = player, damage = 1, skillName = skel.name, damageType = fk.FireDamage }
  end,
})

skel:addEffect(fk.TurnStart, {
  can_refresh = function (self, event, target, player, data)
    return player == target and player:getMark("@@rmt__diaozhuoguimu") ~= 0
  end,
  on_refresh = function (self, event, target, player, data)
    player.room:setPlayerMark(player, "@@rmt__diaozhuoguimu", 0)
  end,
})

return skel
